class Solution {
public:
    vector<vector<int>> levelOrderBottom(TreeNode* root) {
        if (!root)
            return {};
        vector<vector<int>> retnums;
        vector<int> nums;
        queue<TreeNode*> q;
        q.push(root);
        int size = q.size();
        while (!q.empty())
        {
            for (int i = 0; i < size; ++i)
            {
                nums.push_back(q.front()->val);
                if (q.front()->left)
                    q.push(q.front()->left);
                if (q.front()->right)
                    q.push(q.front()->right);
                q.pop();
            }
            retnums.push_back(nums);
            nums.clear();
            size = q.size();
        }
        reverse(retnums.begin(), retnums.end());
        return retnums;
    }
};